<?php
/*
 * 支付回调类
 */

require_once DOCROOT."/resource/wxpay/lib/WxPay.Api.php";
require_once DOCROOT."/resource/wxpay/lib/WxPay.Notify.php";

class Payment_Weixin_Notify extends WxPayNotify
{
	//重写回调处理函数
	public function NotifyProcess($data, &$msg)
	{
        Kohana::$log->add(Log::DEBUG, "PaymentCallback:". print_r($data, TRUE));

		$notfiyOutput = array();
		
        $transactionId = Arr::get($data, 'transaction_id');
        $merchantId    = Arr::get($data, 'mch_id');
		if(empty($transactionId))
        {
			$msg = "输入参数不正确";
			return false;
		}

        $orderNo = Arr::get($data, 'out_trade_no');
        $resultCode = Arr::get($data, 'result_code');
        $returnCode = Arr::get($data, 'return_code');

        if (! empty($orderNo) && $resultCode == 'SUCCESS' && $returnCode == 'SUCCESS')
        {
            $paymentId = 1;
            $trans = Payment_Transaction::instanceByOutTradeNo ($orderNo);
            $trans->notify_paid ('WEIXIN', $transactionId, $merchantId, $resultCode, $returnCode);
            //App_Order::setOrderPaid($orderNo, $transactionId, $paymentId, $merchantId);
        }

		return true;
	}
}
